﻿using System;
using System.Linq;
using NUnit.Framework;

namespace NMA.Infrastructure.NHibernate.Tests.LambdaExpressionHelper
{
    using NMA.Application;    
    using NMA.Domain.Shared;
    using NMA.Domain.Model;
    using NMA.Domain.Model.Service.Application;

    [TestFixture]
    public class LambdaExpressionHelperTest : TestingBase
    {
        private ICategoryFacade _categoryFacade = null;

        protected override void Before_each_test()
        {
            base.Before_each_test();
            _categoryFacade = new CategoryFacade();
        }

        [Test]
        public void Can_execute_right_with_constant_method()
        {
            var result = _categoryFacade.GetBy(y => y.Name == "unit test name 1", typeof(INameEntity<ICategory>));
            
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 1);            
        }

        [Test]
        public void Can_execute_left_with_method()
        {
            var result = _categoryFacade.GetBy(y => y.CreatedDate.CompareTo(DateTime.Now) == 0, typeof(IEntity<ICategory>));

            Assert.IsNotNull(result);
        }

        [Test]
        public void Can_execute_right_with_method()
        {
            var result = _categoryFacade.GetBy(y => y.Id == Guid.NewGuid(), typeof(IEntity<ICategory>));

            Assert.IsNotNull(result);
        }

        protected override void After_each_test()
        {
            base.After_each_test();

            if (_categoryFacade != null)
                GC.SuppressFinalize(_categoryFacade);
        }
    }
}
